package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC424 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        private int[] map = new int[26];

        public int characterReplacement(String s, int k) {
            if (s == null) {
                return 0;
            }
            char[] chars = s.toCharArray();
            int left = 0;
            int right = 0;
            int historyCharMax = 0;
            for (right = 0; right < chars.length; right++) {
                int index = chars[right] - 'A';
                map[index]++;
                historyCharMax = Math.max(historyCharMax, map[index]);
                if (right - left + 1 > historyCharMax + k) {
                    map[chars[left] - 'A']--;
                    left++;
                }
            }
            return chars.length - left;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC424 an = new LC424();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
